home *** CD-ROM | disk | FTP | other *** search
Wrap
#!/usr/bin/perl5 # # pop-account.cgi # # Copyright 1988-1996 Silicon Graphics, Inc. # All rights reserved. # # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.; # the contents of this file may not be disclosed to third parties, copied or # duplicated in any form, in whole or in part, without the prior written # permission of Silicon Graphics, Inc. # # RESTRICTED RIGHTS LEGEND: # Use, duplication or disclosure by the Government is subject to restrictions # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data # and Computer Software clause at DFARS 252.227-7013, and/or in similar or # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished - # rights reserved under the Copyright Laws of the United States. # # $Id: pop-account.frm,v 1.19 1997/06/19 22:25:46 shotes Exp $ require "/usr/OnRamp/lib/OnRamp.pm"; $conf = "/etc/passwd"; $dummy = "/etc/passwd.temp"; $myname = "pop-account.cgi"; $title = "POP3 Mail Accounts"; $popdir = "/usr/pop3"; $js_main = "which = \"none\"; function runSubmit() { // onClick gets processed before onSubmit if(which == \"add\") return runAdd(); if(which == \"delete\") return runDelete(); return (true); } function markAdd() { which = \"add\"; } function markDelete() { which = \"delete\"; } function markOther() { which = \"none\"; } function runAdd() { form = document.POPForm; if (!testLogin(form)) return (false); return (true); } function runDelete() { Ctrl = document.POPForm.chosen; none = true; for(i = 0; i < Ctrl.length; i++) { if (Ctrl.options[i].selected) { none = false; break; } } if(none) { errorBox (Ctrl, \"No account selected.\"); return (false); } return (true); } function testLogin(form) { Ctrl = form.new_account; if (Ctrl.value == \"\") { errorBox (Ctrl, \"To add a new account, first enter a login name for \\nthe account, then click the \\\"Add New Account\\\" button.\"); return (false); } error = testLoginChars(Ctrl.value); if (error == 1) { errorBox (Ctrl, \"The login name cannot be more \\nthan 8 characters long.\"); return (false); } if (error == 2) { errorBox (Ctrl, \"The login name cannot contain the \" + illegal + \" character.\"); return (false); } if (error == 3) { errorBox (Ctrl, \"The login name cannot contain spaces.\"); return (false); } return (true); } function testLoginChars(word) { if (word.length > 8) return 1; loginChars = \"_-\.{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\"; for(j = 0; j < loginChars.length; j++) { c = loginChars.charAt(j); if (word.indexOf(c, 0) != -1) { illegal = c; return 2; } } for (c = 0; c < word.length; c++) { if (word.charAt(c) == ' ') return 3; } return 0; } function errorBox (Ctrl, ErrorMessage) { alert (ErrorMessage); Ctrl.focus(); return; }"; $js_add = "which = \"none\"; function runSubmit() { // onClick must get processed before onSubmit if(which == \"add\") return runAdd(); return (true); } function markAdd() { which = \"add\"; } function markOther() { which = \"none\"; } function runAdd() { form = document.AddForm; // JavaScript can't look at password fields. return (true); } function errorBox (Ctrl, ErrorMessage) { alert (ErrorMessage); Ctrl.focus(); return; }"; print "Content-type: text/html\n\n"; &get_fields; &getAccounts; if (%fld) { $fld{'chosen'} =~ /([\w.-]+)/; $fld{'chosen'} = $1; $help = $document_root . $ENV{"SCRIPT_NAME"}; $help =~ s/cgi$/hlp/; exec $help if ($fld{'help'} eq "Help"); if ($fld{'add'}) { &formValid_add; @test = getpwnam($fld{'new_account'}); &error(2,"Account already exists.") if $test[0]; $val{'login'} = $fld{'new_account'}; &addAccount; } elsif ($fld{'delete'}) { &error(2,"No account selected.") if !$fld{'chosen'}; $message = qq|Click "Ok" to save changes.|; &generic($fld{'chosen'}); } elsif ($fld{'doit'}) { &tryToDelete; &getAccounts; if (!$message) { $message = "No changes made."; } &generic; } elsif ($fld{'doadd'}) { &formValid_doAdd; &doAdd; &getAccounts; &generic; } else { $message = "Use buttons to submit form."; &generic; } } else { $NSstatus = &checkForNS; if ($NSstatus) { &title_block($title); &header_block($title); print "<i>NS Mail is currently running. To enable POP3 Mail, first disable NS Mail.</i>"; } else { &generic; } } sub checkForNS { local($mail_process) = "NscpMail"; local($ret) = 0; open(PSNS, "/bin/ps -ef |"); while (<PSNS>) { if ($_ =~ m:$mail_process:) { $ret = 1; } } close(PSNS); $ret; } sub formValid_add { &error(1,qq|To add new account, first enter in login name for new account, then click "Add New Account" button.|) if !$fld{'new_account'}; &error(1,qq|Invalid login name.|) if $fld{'new_account'} =~ /$LOGINCHARS/o; } sub formValid_doAdd { if (!$fld{'password'}) { &error(0,"You must enter a password."); } if ($fld{'password'} ne $fld{'passcheck'}) { &error(0,"Input passwords not equivalent."); } &error(0,"Invalid login name.") if $fld{'login'} =~ /$METACHARS/o; } sub error { &error_block($_[1]); %val = %fld; if ($_[0] == 0) { &addAccount; } if ($_[0] == 1 || $_[0] == 2) { undef @_; &generic; } exit 0; } sub tryToDelete { $account = $fld{'del_name'}; if ($account eq "") { return; } open(IN,"< $conf"); open(OUT,"> $dummy"); while(<IN>) { $line = $_; if ($line =~ /^\s*\#/) { print OUT $line; next; } @items = split(/:/,$line); if ( ($items[5] =~ /^$popdir/) && $items[0] eq $account) { next; } else { print OUT $line; } } close(IN); close(OUT); rename($dummy, $conf); $message = "Account deleted."; } sub doAdd { local($lgname) = $fld{'login'}; $userdir = $popdir."/$lgname"; &add_password($lgname,$fld{'password'},2000,20,$lgname." pop3", $userdir, "/bin/false"); if (! -d $popdir) { mkdir($popdir, 0755); } mkdir($userdir, 0755); chown((getpwnam($lgname))[2,3], $userdir); $message = "New account added."; } sub addAccount { &js_title_block($title,$js_add); &header_block("Add New POP3 Mail Account"); print "<form action=$myname method=post name=AddForm onSubmit=\"return runSubmit()\">\n"; print "<center><table>"; print "<input type=hidden name=login value=$val{'login'}>"; print "<tr><th align=left>Login name:</th><td><tt>", $val{'login'},"</tt></td></tr>"; print "<tr><th align=left>Password:</th><th align=left>"; print qq|<input type=password name="password" size=20>|; print "</th></tr>"; print "<tr><th align=left>(Password again):</th><th align=left>"; print qq|<input type=password name="passcheck" size=20>|; print "</th></tr>"; print "</table></center><br>"; print &js_buttons('doadd','Ok','onClick="markAdd()"','onClick="markOther()"'); print "</form></body></html>"; } sub getAccounts { $i = 0; open(IN,"< $conf"); while(<IN>) { $line = $_; if ($line =~ /^\s*\#/) { next; } @items = split(/:/,$line); chop $items[5]; if ($items[5] =~ /^$popdir/) { $name[$i] = $items[0]; $i++; } } $number = $i; close(IN); } sub generic { if (! -e "/usr/freeware/lib/popper") { print "<center><h2>POP3 Mail Server</h2></center>\n", "<i>POP3 Mail Server software is not installed on this system", " by default. Please install the </i><b>fw_BSDqpopper</b><i>", " from the freeware CD.</i>"; exit 0; } &js_title_block($title,$js_main); &header_block($title); %val = %fld; if (!$number && !$message) { $message = "No existing POP3 accounts."; } print "<i>$message</i>"; print "<form action=$myname method=post name=POPForm onSubmit=\"return runSubmit()\">\n"; if ($_[0]) { print qq|<input type=hidden name="del_name" value=$_[0]>|; } print "<center><table width=400>"; print "<tr><td></td><th align=left>Login Name</th></tr>"; print qq|<tr><td><input type=submit name="add" value="Add New Account" onClick="return markAdd()"> </td><td><input name="new_account" value="$val{'new_account'}" size=20></td></tr>|; if ($number) { undef @locList; for ($i=0;$i<$number;$i++) { if ($_[0] ne $name[$i]) { push(@locList,$name[$i]); } } print qq|<tr><td valign=top><input type=submit name="delete" value="Delete Selected Account" onClick="return markDelete()"></td><td>|; print &choice_list(*locList,"chosen",20); print "</td></tr>"; } print "</table></center><br>"; print &js_buttons('doit','Ok','onClick="markOther()"','onClick="markOther()"'); print "</form></body></html>"; }